import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/11 21:18
 * @description 双指针，统计T和F的个数
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.maxConsecutiveAnswers("TTFTTFTTT", 1);
    }
    public int maxConsecutiveAnswers(String answerKey, int k) {
        int n = answerKey.length();
        char[] A = answerKey.toCharArray();
        int left = 0, right = 0, T = 0, F = 0;
        int ans = 0;
        while (right < n) {
            if (A[right] == 'T') {
                T++;
            }else {
                F++;
            }
            while (T > k && F > k) {
                if (A[left] == 'T') {
                    T--;
                }else {
                    F--;
                }
                left++;
            }
            ans = Math.max(ans, right - left + 1);
            right++;
        }
        return ans;
    }
}
